package com.mi.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mi.bean.Manager;
import com.mi.service.impl.LoginServiceImpl;
import com.mi.service.impl.ManagerRegisterServiceImpl;
import com.mi.utils.MyUtils;

/**
 * Servlet implementation class CustomerRegisterAction
 */
@WebServlet("/ManagerRegisterAction")
@MultipartConfig(maxFileSize=1024*1024*5)
public class ManagerRegisterAction extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 取出客户端发送的表单数据
		// 调用方法获取映射表单数据的实体类的实例
		Manager managerA = MyUtils.convertFormData2Bean(request, Manager.class);

		// 2、调用service层,将实体类中的数据保存到数据库中
		int i = MyUtils.getInstance(ManagerRegisterServiceImpl.class).saveOrUpdateAdminInf(managerA);
		
		// 根据保存结果 进行页面转发
		if(i > 0) {
			// 保存成功,跳转到登录页面
			System.out.println("用户名："+managerA.getManager_name());
			System.out.println("用户密码："+managerA.getManager_psw());
			request.getRequestDispatcher("WEB-INF/logined/adminManage/jumpweb.jsp").forward(request, response);
	// request.getRequestDispatcher("WEB-INF/login.jsp").forward(request, response);
			
		}else {
			// 保存失败
			request.getRequestDispatcher("WEB-INF/register.jsp").forward(request, response);
		}

	}

}
